package com.hurl.library.spider;

public class CharRule implements UrlRule{
	private char minChar;
	private char maxChar;

	private char nextChar;
	private String previous;
	
	public CharRule(char minChar,char maxChar){
		if(minChar>maxChar){
			throw new ConfigurationException("最小字符不能大于最大字符！");
		}

		this.minChar=minChar;
		this.maxChar=maxChar;
		
		this.beforeFirst();
	}
	
	public void beforeFirst(){
		previous = null;
		nextChar=minChar;
	}
	
	@Override
	public boolean hasNext() {
		return (Integer.parseInt(Character.toString(nextChar))+1)<=maxChar;
	}
	@Override
	public String next() {
		if(!hasNext()){
			return null;
		}
		String res = Character.toString(nextChar);
		previous = res;
		nextChar = (char)(Integer.parseInt(res)+1);
		return res;
	}

	@Override
	public String previous() {
		return previous;
	}
}
